package exceptions;

import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;

/**
 * Generieke SQL foutmelding.
 */
public class GenericSQLException extends WebApplicationException {

    private final static Status status = Status.INTERNAL_SERVER_ERROR;

    public GenericSQLException() {

        super(Response.status(status).entity(buildMessage("")).type(MediaType.TEXT_PLAIN).build());
    }

    public GenericSQLException(String message) {

        super(Response.status(status).entity(buildMessage(message)).type(MediaType.TEXT_PLAIN).build());
    }

    private static String buildMessage(String message) {

        String statusString = "HTTP status " + status.getStatusCode() + " - " + status.name();
        String errorString = "GenericSQLException: " + message;

        return (statusString + "\n\n" + errorString);
    }
}
